/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server;

import static com.lineage.server.model.identity.L1SystemMessageId.$1007;
import static com.lineage.server.model.identity.L1SystemMessageId.$1020;
import static com.lineage.server.model.identity.L1SystemMessageId.$1021;
import static com.lineage.server.model.identity.L1SystemMessageId.$1023;
import static com.lineage.server.model.identity.L1SystemMessageId.$1065;
import static com.lineage.server.model.identity.L1SystemMessageId.$1292;
import static com.lineage.server.model.identity.L1SystemMessageId.$1300;
import static com.lineage.server.model.identity.L1SystemMessageId.$1306;
import static com.lineage.server.model.identity.L1SystemMessageId.$1309;
import static com.lineage.server.model.identity.L1SystemMessageId.$1310;
import static com.lineage.server.model.identity.L1SystemMessageId.$1384;
import static com.lineage.server.model.identity.L1SystemMessageId.$181;
import static com.lineage.server.model.identity.L1SystemMessageId.$312;
import static com.lineage.server.model.identity.L1SystemMessageId.$338;
import static com.lineage.server.model.identity.L1SystemMessageId.$481;
import static com.lineage.server.model.identity.L1SystemMessageId.$563;
import static com.lineage.server.model.identity.L1SystemMessageId.$647;
import static com.lineage.server.model.identity.L1SystemMessageId.$79;

import java.util.concurrent.ConcurrentHashMap;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.packetserver.S_Message_YN;
import com.lineage.server.packetserver.S_PacketBox;
import com.lineage.server.packetserver.S_ServerMessage;
import com.lineage.server.packetserver.S_SystemMessage;
import com.lineage.server.packetserver.ServerBasePacket;

/**
 * Class <code>PacketCreate</code> 封包产生器.
 * 
 * @author jrwz
 * @version 2012-4-5上午01:35:21
 * @see com.lineage.server
 * @since JDK1.7
 */
public final class PacketCreate {
    /** 实例. */
    private static PacketCreate _instance;
    /** 公用封包集合. */
    private static ConcurrentHashMap<String, ServerBasePacket> packetMap;

    static {
        packetMap = new ConcurrentHashMap<String, ServerBasePacket>();

        packetMap.put("盟主正在呼唤你，你要接受他的呼唤吗？(Y/N)", new S_Message_YN(729, ""));

        packetMap.put("你觉得舒服多了", new S_PacketBox(S_PacketBox.MSG_FEEL_GOOD));

        packetMap.put("道具异常", new S_SystemMessage("你的道具状态异常，已被系统自动删除。"));

        // packetMap.put("你觉得舒服多了", new S_ServerMessage($77));
        packetMap.put("没有任何事情发生", new S_ServerMessage($79));
        packetMap.put("无法变成你指定的怪物", new S_ServerMessage($181));
        packetMap.put("你还不能学习法术", new S_ServerMessage($312));
        packetMap.put("你的 魔力 渐渐恢复。", new S_ServerMessage($338, "$1084"));
        packetMap.put("属性最大值只能到35", new S_ServerMessage($481));
        packetMap.put("你无法在这个地方使用", new S_ServerMessage($563));
        packetMap.put("你感觉到魔力恢复速度加快", new S_ServerMessage($1007));
        packetMap.put("已申诉", new S_ServerMessage($1020));
        packetMap.put("请稍后再进行申诉", new S_ServerMessage($1021));
        packetMap.put("请选择要申诉的角色", new S_ServerMessage($1023));
        packetMap.put("将发生神秘的奇迹力量", new S_ServerMessage($1065));
        packetMap.put("由于狩猎获得的经验值量增加了", new S_ServerMessage($1292));
        packetMap.put("神秘力量的影响正在发生。", new S_ServerMessage($1300));
        packetMap.put("此装备上是无法使用魔法的。", new S_ServerMessage($1306));
        packetMap.put("此装备无法使用装备保护卷轴。", new S_ServerMessage($1309));
        packetMap.put("由于受到了魔法力量的保护，虽然产生激烈的 蓝色的 光芒，但是装备没有消失。",
                new S_ServerMessage($1310));
        packetMap.put("目前状态中无法变身", new S_ServerMessage($1384));
        packetMap.put("这附近的能量影响到瞬间移动。在此地无法使用瞬间移动。", new S_ServerMessage($647));
    }

    /**
     * 实例为空时才产生一个(多线程下的单例模式).
     * 
     * @return 实例
     */
    public static synchronized PacketCreate get() {
        if (_instance == null) {
            _instance = new PacketCreate();
        }
        return _instance;
    }

    /** 封包产生器. */
    private PacketCreate() {
    }

    /**
     * 取得封包.
     * 
     * @param s
     *            要发送的封包名称
     * @return 集合内的封包名称
     */
    private ServerBasePacket getPacket(final String s) {
        return packetMap.get(s);
    }

    /**
     * 发送单体封包.
     * 
     * @param pc
     *            对象
     * @param s
     *            封包名称
     */
    public void sendSinglePackets(final L1PcInstance pc, final String s) {
        if (!s.equals("")) {
            final ServerBasePacket msg = this.getPacket(s);
            pc.sendPackets(msg);
        }
    }
}
